<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['type']){
	$_SESSION['choose_source']['type']=trim($_RQ['type']);
}
if($_RQ['source_type']){
	$_SESSION['choose_source']['source_type']=trim($_RQ['source_type']);
}
$return['type']=$_SESSION['choose_source']['type']?:'one';
$return['source_type']=$_SESSION['choose_source']['source_type']?:'image';
$tabs=array(
	array('op'=>'local','title'=>'本地上传'),
	array('op'=>'remote','title'=>'提取网络图片'),
	array('op'=>'list','title'=>'图片库选取'),
);
$return['tabs']=$tabs;

if($_RQ['op']=='local' || $_RQ['op']=='remote' || $_RQ['op']=='srcurl'){
	$return['item']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'type'=>'image');
	if(isset($_RQ['group_id']) && $_RQ['group_id']!=-1){
		$params['group_id']=intval($_RQ['group_id']);
		$return['params']['group_id']=$_RQ['group_id'];
	}else{
		$return['params']['group_id']=-1;
	}
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if($_SESSION['this']=='custom'){
		$params['mid']=$_SESSION['uid'];
	}
	$fields=array('title','attachment');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('core_attachment',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['groups']=pdo_getall('core_attachment_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$nogroup=array('id'=>0,'title'=>'未分组');
	array_unshift($return['groups'],$nogroup);
	$all=array('id'=>-1,'title'=>'全部');
	array_unshift($return['groups'],$all);
	exi($return);
}